package org.example;

//写一个泛型类实现一个方法：求指定类型的数组最大值
class Alg<T extends Comparable<T>> {
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i].compareTo(max) > 0){//Object之间不能比较
                max = array[i];
            }
        }
        return max;
    }
}
public class Max {
    public static void main(String[] args) {
        Alg<Integer> stringAlg = new Alg<>();
        Integer[] arr = {1, 0, 6, 5, 3};
        Integer ret = stringAlg.findMax(arr);
        System.out.println(ret);

        /**
         * t(1) = t(0) + 1 = 2;
         * t(2) = t(1) + 2 = 4;
         * t(3) = t(2) + 3 = 7;
         * t(4) = t(3) + 4 = 11;
         */
        //t(n) = t(n-1) + n;//t(0)=1
        //t
    }
}
